﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Scripting.Hosting;
using Microsoft.Scripting;
using System.Xml.Serialization;
using System.Drawing.Imaging;
using System.Drawing;
namespace MetaNote.Model
{
    [Serializable()]    
    public class Macro
    {
        public string SourceCode { get; set; }
        public string Title { get; set; }

        [XmlIgnore()] //not relevant for serialization
        public bool IsCompiled { get; private set; }

        [XmlIgnore()] //not reusable across serialization (MarshalByRefObject)
        public ScriptSource CompiledScript { get; private set; }

        public Guid Key { get; set; }

        public int Sequence { get; set; }

        public string ParentName { get; set; }

        public string OwnerName { get; set; }

        //TODO: get image to be serialized into settings file!
        public Image Image { get; set; }

        /// <summary>
        /// Compiles the source code into a compiled script, using the specified engine.
        /// </summary>
        /// <param name="engine">The engine.</param>
        internal void Compile(ScriptEngine engine)
        {
           this.CompiledScript = engine.CreateScriptSourceFromString(this.SourceCode, SourceCodeKind.Statements);
           this.IsCompiled = true;
        }

        public override string ToString()
        {
            //return base.ToString();
            return Title;
        }
    }    
}
